package com.wipz.eoa.iphone.myworkmanagent.mywork.myworktype;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.wipz.eoa.iphone.BaseServiceImpl;
import com.wipz.eoa.iphone.util.UUIDHexGenerator;

/**
 * 委托类型业务接口实现类
 * @author 张涛
 * @date 2012-2-6
 */
public class WorkTypeServiceImpl extends BaseServiceImpl implements IWorkTypeService {

	@SuppressWarnings("unchecked")
	@Override
	public Map delete(Map params) {
		Map result = (Map)super.queryOne("workType.queryByType",params);
		Map msg = new HashMap();
		String message = "";
		boolean flag = false;
		if (result==null||result.isEmpty()) {
			super.delete("workType.delete", (String) result.get("ID"));
			message = "删除成功！";
			flag = true;
		} else {
			message="该委托类型被使用中，删除失败！";
		}
		msg.put("message", message);
		msg.put("flag", flag);
		return msg;
	}

	@SuppressWarnings("unchecked")
	@Override
	public int addOrUpdate(Map params) {
		String id = (String)params.get("ID");
		if (!"".equals(id) && id != null){//更新
			return super.update("workType.update", params);
		}else{//添加
			Map result = (Map) super.queryOne("workType.check", params);
			
			if(result == null || result.isEmpty()){
				id = UUIDHexGenerator.getInstance().generate();
				params.put("ID", id);
				return super.insert("workType.insert", params);
			}else{
				return -1;
//				throw ToftException.ThrowToftException("此类型名称已存在，请检查后再保存！");
			}
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List queryAll(Map params) {
		return super.queryList("workType.queryAll", params);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Map view(Map params) {
		return (Map) super.queryOne("workType.queryById", params);
	}

}
